#include "logservice.h"

LogService::LogService()
{
}

QByteArray LogService::execute (QDataStream &in)
{
    QByteArray block;
    QDataStream out(&block, QIODevice::WriteOnly);

    QString requestType;

    in >> requestType;

    if(requestType == "LOG")
    {

        QString log;
        in >> log;

        QFile logFile("Log.txt");
        if(logFile.open(QFile::WriteOnly));
        {
            QDataStream fileOut(&logFile);
            fileOut << log;
            logFile.close();
        }

        out << quint16(0) << QString ("OK");
        out.device()->seek(0);
        out << quint16(block.size() - sizeof(quint16));
    }
    return block;
}
